<template>
  <a-table
    :columns="columns"
    :data-source="tableList"
    :pagination="pagination"
    :scroll="{ y: '780px' }"
    @change="handleChangePage"
  >
    <template #bodyCell="{ record, column }">
      <template v-if="column.dataIndex === 'packLog'">
        {{ record.packLog[0] ? record.packLog[0].name : '-' }}
      </template>
      <template v-if="column.dataIndex === 'packLog.id'">
        {{ record.packLog[0] ? record.packLog[0]._id : '-' }}
      </template>
      <template v-if="column.dataIndex === 'payPrice'">
        {{ (record.payPrice / 100).toFixed(2) }}
      </template>

      <template v-if="column.dataIndex === 'updatedAt'">
        {{ dayjs(record.updatedAt).format('YYYY-MM-DD HH:mm:ss') }}
      </template>
      <template v-if="column.dataIndex === 'status'">
        <span :class="record.status">{{
          statusText[record.status as keyof typeof statusText]
        }}</span>
      </template>
    </template>
  </a-table>
</template>
<script lang="ts" setup>
import dayjs from 'dayjs'
import type { TTable } from './type.dict'
const statusText = {
  PAYING: '支付中',
  SUCCESS: '购买成功',
  ERROR: '付款失败',
}
const emit = defineEmits(['changePagination'])
defineProps<{
  tableList: TTable[]
  pagination: {
    total: number
    current: number
    pageSize: number
  }
}>()
const handleChangePage = (e: { current: number; pageSize: number }) => {
  emit('changePagination', {
    pageSize: e.pageSize,
    current: e.current,
  })
}
const columns = [
  {
    title: '购买礼包',
    dataIndex: 'packLog',
  },
  {
    title: '礼包ID',
    dataIndex: 'packLog.id',
  },
  {
    title: '支付价格',
    dataIndex: 'payPrice',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'updatedAt',
    width: 180,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 90,
  },
]
</script>
<style lang="stylus" scoped>
@import "@/assets/antgloab-ant.css";
.PAYING{
  color #999
}
.SUCCESS {
  color: #1677ff;
}
.ERROR{
  color red
}
.red{
  color red
}
.modal-center {
  display flex
  flex-direction column
  align-items center
  justify-content center
  margin 46px 0 40px

  .modal-text {
    margin 16px 0 56px
    font-size 16px
    font-weight 500
  }

  .modal-btn {
    width 200px
    height 46px
    border-radius: 4px
    background #3483FF
    font-weight 500
    font-size 16px
  }
}

:deep(.ant-table-body::-webkit-scrollbar) {
  width: 0;
}

.header_text {
  color: rgba(0, 0, 0, 0.88);
  font-weight: 600;
}
</style>
